<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>标注和标注图层-海量点</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
    <style>
        html, body, #container {
            height: 100%;
            width: 100%;
            margin: 0;
        }
        .amap-info-window{
            width: 150px;
            background: #fff;
            border-radius: 3px;
            padding: 3px 7px;
            box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5);
            position: relative;
        }
        .amap-info-sharp{
            position: absolute;
            top: 21px;
            bottom: 0;
            left: 50%;
            margin-left: -8px;
            border-left: 8px solid transparent;
            border-right: 8px solid transparent;
            border-top: 8px solid #fff;
        }
    </style>
	<style>
	body,html{ margin:0;padding:0;font:12px/16px Verdana,Helvetica,Arial,sans-serif;width: 100%;height: 100%}
	.container{
	  height: 100%
	}
	</style>
</head>
<body>
<div id="container"></div>

<div class="info">
    <h4>海量点展示</h4>
    <p>模式：<span id="mapView">3D</span></p>
	<div id="container" style="width:100%; height:100%;resize:both;"></div>
    <!-- <p>海量点数量：<span id="massNumber">x个点</span></p> -->
	<div id="container" class="map"></div>
	<div class="input-card">
	    <h4>左击获取经纬度：</h4>
	    <div class="input-item">
	      <input type="text" readonly="true" id="lnglat">
	    </div>
	</div>
 </div>
<script type="text/javascript"
        src="https://webapi.amap.com/maps?v=1.4.15&key=91c1aeee49ce767cb2c2d637607ac8ca"></script>
<!-- <script type="text/javascript" src="https://a.amap.com/jsapi_demos/static/demo-center/data/mock_position.js"></script> -->
<script src="../../js/application.js"></script>
<script type="text/javascript" src="../../js/jquery-3.3.1.js" ></script>
<script type="text/javascript" src="../../layui/layui.all.js" charset="utf-8"></script>
<script type="text/javascript" src="../../js/mapNum.js" charset="utf-8"></script>
<script type="text/javascript">
    var map = new AMap.Map('container', {
		resizeEnable: true,
		rotateEnable:true,
		pitchEnable:true,
		zoom: 15,
		pitch:80,
		rotation:-15,
		viewMode:'3D',//开启3D视图,默认为关闭
		buildingAnimation:true,//楼块出现是否带动画
		expandZoomRange:true,
		zooms:[3,20],
		center: [102.999165,25.248093],
		
        mapStyle: 'amap://styles/fresh',//加载地图样式light，fresh，grey,blue
    });

    map.on('complete', function () {
        var viewData = {'2D': 3E3, '3D': 3E4};
        var curViewMode = map.getViewMode_();

        // 创建 AMap.LabelsLayer 图层
        var layer = new AMap.LabelsLayer({
            zooms: [3, 20],
            zIndex: 1000,
            // 关闭标注避让，默认为开启，v1.4.15 新增属性
            animation: false,
            // 关闭标注淡入动画，默认为开启，v1.4.15 新增属性
            collision: false
        });

        // 将图层添加到地图
        map.add(layer);

        var markers = [];
        var positions = Positions.slice(0, viewData[curViewMode]);
			
        var icon = {
            type: 'image',
            image: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png',
            size: [6, 9],
            anchor: 'bottom-center',
            angel: 0,
            retina: true
        };

        for (var i = 0; i < positions.length; i++) {
            var curPosition = positions[i];
            var curData = {
                position: curPosition,
                icon
            };

            var labelMarker = new AMap.LabelMarker(curData);

            markers.push(labelMarker);
        }
        
        // 一次性将海量点添加到图层
        layer.add(markers);
        
        // 普通点
        var normalMarker = new AMap.Marker({
            offset: new AMap.Pixel(-75, -40),
        });
        // 事件
        layer.on('mouseover', function(e){
            var position = e.data.data && e.data.data.position;

            if(position){
                normalMarker.setContent(
                    '<div class="amap-info-window">'
                        + position +
                        '<div class="amap-info-sharp"></div>' +
                    '</div>');
                normalMarker.setPosition(position);
                map.add(normalMarker); 
            }
        });

        layer.on('mouseout', function(){
            map.remove(normalMarker);
        });
        
        var mapViewElement = document.getElementById('mapView');
        var massNumberElement = document.getElementById('massNumber');
        mapViewElement.innerHTML = curViewMode;
        //massNumberElement.innerHTML = viewData[curViewMode];
		
		
		//为地图注册click事件获取鼠标点击出的经纬度坐标
		map.on('click', function(e) {
			document.getElementById("lnglat").value = e.lnglat.getLng() + ',' + e.lnglat.getLat()
		});
		/* var auto = new AMap.Autocomplete({
			input: "tipinput"
		}); */
		//AMap.event.addListener(auto, "select", select);//注册监听，当选中某条记录时会触发
		function select(e) {
			if (e.poi && e.poi.location) {
				map.setZoom(15);
				map.setCenter(e.poi.location);
			}
		}
    });
</script>
</body>
</html>